/** 
 * Title: Optimal Parking
 * URL: http://uva.onlinejudge.org/external/113/11364.html
 * Resources of interest:
 * Solver group: David
 * Contact e-mail: dncampo at gmail dot com
 * Description of solution:
   + Se ordena la entrada y se suman las diferencias sucesivas de cada una de 
   estas.
	
**/


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	unsigned n_cases;
	cin >> n_cases;
	
	for (unsigned i = 0; i < n_cases; i++){
		unsigned n;
		cin >> n;
		vector<unsigned> data(n);
		
		for (unsigned j = 0; j < n; j++) cin >> data[j];
		
		sort (data.begin(), data.end());
		
		unsigned sum = 0;
		for (unsigned k = 1; k < n; k++) sum += data[k] - data[k - 1];
		sum += data[n - 1] - data[0];
		
		cout << sum << endl;
		
	}
	return 0;
}

